package com.seata.stockseata.controller;


import com.seata.stockseata.domain.User;
import com.seata.stockseata.service.UserService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author business
 * @since 2023-04-02
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {


    @Resource
    UserService userService;

    @PostMapping("saveStockUser")
    @GlobalTransactional
    public Map<String, Object> saveStockUser(@RequestBody User user) {
        Map<String, Object> map = new HashMap<>();

        user.setName("李四");
        user.setSex("女");
        if (userService.save(user)) {
            map.put("code", 200);
            map.put("message", "成功");
            map.put("data", user);
            throw new RuntimeException("失败");
        }

        return map;
    }
}

